﻿Imports Heren.Common.Forms.Editor
Imports Heren.Common.Forms
Imports Heren.Common.ScriptEngine.Script
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports Heren.Common.Forms.Runtime
Imports System.Text
Imports Heren.Common.Libraries

Public Class 压疮申报单 : Inherits AbstractRuntimeHandler
    ''﻿****************************************************************
    '' 这是护理电子病历表单后台运行支持脚本
    '' 注意：这是Visual Basic脚本，您可以不区分大小写 
    '' 请不要修改系统提供的方法名，以及方法名前面的Overrides关键字
    '' Script Language : Visual Basic
    '' Author : YangMingkun, Date : 2012-3-18
    '' Copyright (C) Heren Health Services (SUPCON) Co.,Ltd.
    ''****************************************************************


    '表单脚本初始化
    Public Overrides Sub Initialize()
        'Me.ShowMessage("表单已完成加载!")
        '在此函数中来查询和设置表单中的相关数据
        '可以调用GetSystemContext函数获取系统中已有数据，也可以从数据库中读取其他任意数据

        Dim value As Object = ""
        Me.GetSystemContext("病历状态", value)
        If (Value IsNot Nothing) Then
            '       shOWmESSAGE("病历状态：" +value.toString())
        End If
        If value = "新建" Then
            Me.RefreshPatientInfo()
        End If
        Me.SubmitBtnTextControl()

        '用于控制多个申报类型选择后，在勾掉一个时，barden评分被隐藏
        For index As Integer = 1 To 4
            Me.registerEvent("XCheckBox" & index, "CheckedChanged", "XCheckBox1_CheckedChanged")
        Next
        Dim time As Date = Date.now
        'showmessage("zhuanguishijian"+time.toShortDateString())
        Me.SetControlText("XTextBox25", time.toShortDateString())
        Me.SetControlText("XTextBox26", time.toShortDateString())
        '添加科室选择
        Me.AddContextMenu("选择转入科室")
        Me.AddContextMenuItem("选择转入科室", "选择转入科室", "SelectDeptClick")

    End Sub
    '用户选中的行
    Dim rowIndex As Integer = 0
    Private Sub SelectDeptClick(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim datagrid As XDataGrid = Me.FindControl("XDataGrid6")
        If datagrid Is Nothing OrElse datagrid.rows.count <= 0 Then
            Exit Sub
        End If

        Dim result As DataTable = Nothing
        Me.RaiseCustomEvent(sender, "科室选择对话框", False, Nothing, result)
        If result IsNot Nothing Then
            'showmessage(Me.GetFieldValue(result, 0, "dept_name"))
            datagrid.rows(rowIndex).Cells(1).value = Me.GetFieldValue(result, 0, "dept_name")
        End If

    End Sub
    Private Sub XCheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        If IsCheckButtonChecked("XCheckBox1") OrElse IsCheckButtonChecked("XCheckBox2") OrElse IsCheckButtonChecked("XCheckBox3") _
           OrElse IsCheckButtonChecked("XCheckBox4") Then
            Me.SetControlVisible("XPanel13", True)
        Else
            Me.SetControlVisible("XPanel13", False)
        End If
    End Sub

    Public Sub RefresheTime()
        Dim time As datetime
        Dim dtShangXian2 As New DateTime(2013, 1, 21, 8, 0, 0)
        Me.getSystemContext("记录时间", time)
        '      showmessage(time.tostring() & "=" & dtShangXian2.tostring())
        Dim control As control = Me.FindControl("XCheckBox1")
        Dim control1 As control = Me.FindControl("XCheckBox2")
        Dim control2 As control = Me.FindControl("XCheckBox3")
        Dim control3 As control = Me.FindControl("XCheckBox4")
        Dim control4 As control = Me.FindControl("XRadioButton7")
        Dim control5 As control = Me.FindControl("XRadioButton8")
        Dim control6 As control = Me.FindControl("XRadioButton9")
        Dim control7 As control = Me.FindControl("XRadioButton10")
        If time < dtShangXian2 Then

            control.visible = False
            control1.visible = False
            control2.visible = False
            control3.visible = False
            control4.visible = True
            control5.visible = True
            control6.visible = True
            control7.visible = True
        Else
            control.visible = True
            control1.visible = True
            control2.visible = True
            control3.visible = True
            control4.visible = False
            control5.visible = False
            control6.visible = False
            control7.visible = False
        End If
    End Sub
    Private Sub RefreshPatientInfo()

        Dim Grid1 As XDataGrid = CType(Me.FindControl("XDataGrid1"), XDataGrid)
        Dim Grid4 As XDataGrid = CType(Me.FindControl("XDataGrid4"), XDataGrid)
        For rowIndex As Integer = 0 To Grid1.Rows.count - 1
            '      Me.SetCellValue("XDataGird1",row,2," cm× cm")
            Dim row As DataGridViewRow = Grid1.rows(rowIndex)
            If row.Cells(1).value.trim() = "" Then
                row.Cells(1).value = " cm× cm"
            End If
        Next

        For rowIndex As Integer = 0 To Grid4.Rows.count - 1
            '      Me.SetCellValue("XDataGird1",row,2," cm× cm")
            Dim row As DataGridViewRow = Grid4.rows(rowIndex)
            If row.Cells(1).value.trim() = "" Then
                row.Cells(1).value = " cm× cm"
            End If
        Next

        Dim value As Object = ""


        Me.GetSystemContext("病人姓名", value)
        '        shOWmESSAGE("病人姓名：" +value.toString())
        Me.SetControlText("XTextBox17", value)

        Me.GetSystemContext("病人性别", value)
        Me.SetControlText("XTextBox16", value)

        Me.GetSystemContext("病人年龄", value)
        Me.SetControlText("XTextBox15", value)

        Me.GetSystemContext("床号", value)
        Me.SetControlText("XTextBox13", value)

        Me.GetSystemContext("住院号", value)
        Me.SetControlText("XTextBox14", value)

        Me.GetSystemContext("就诊科室名称", value)
        Me.SetControlText("XTextBox12", value)
        Dim userName As String = ""
        Me.GetSystemContext("用户姓名", userName)
        Me.SetControlText("XTextBox19", userName)
        Me.SetControlText("XTextBox22", userName)
        Me.SetControlText("XTextBox23", userName)
        Dim time As Date = Date.now
        Dim XDateTime3 As XDateTime = Me.FindControl("XDateTime3")
        XDateTime3.value = time

        '        Me.GetSystemContext("入院时间", value)
        ''       shOWmESSAGE("入院时间：" +value.toString())
        '       Me.SetControlText("XTextBox4", CDate(value).ToString("yyyy年M月d日 hh:mm:ss"))
        '       
        Dim pid As String = ""
        Me.GetSystemContext("病人ID号", pid)

        Dim vid As String = ""
        Me.GetSystemContext("入院次", vid)

        Dim sql As New StringBuilder
        sql.appendformat("select diagnosis from pats_in_hospital@link_emr where patient_id='{0}' and visit_id='{1}'", pid, vid)
        Dim data As dataset = Nothing
        If Me.executequery(sql.tostring(), data) Then
            Me.SetControlText("XTextBox18", Me.GetFieldValue(data, 0, 0))

        End If


    End Sub
    '当用户在界面上请求获取表单摘要数据时调用此方法
    Public Function GenerateSummary1() As String
        Dim strSummary As New StringBuilder
        Dim control As Control = Me.FindControl("XTextBox17")
        If control IsNot Nothing Then
            strSummary.Append("姓名=" + control.Text)
        End If

        control = Me.FindControl("XTextBox16")
        If control IsNot Nothing Then
            strSummary.Append("性别=" + control.Text)
        End If
        control = Me.FindControl("XTextBox15")
        If control IsNot Nothing Then
            strSummary.Append("年龄=" + control.Text)
        End If

        Return strSummary.ToString()
    End Function


    '获取关键数据列表
    Public Overrides Function GetKeyDataList() As List(Of KeyData)
        'showmessage("GetKeyDataList")
        Dim keyDataList As New List(Of KeyData)
        Dim shenqing As XDateTime = CType(Me.FindControl("XDateTime3"), XDateTime)

        '科室
        Dim pat_dept As XTextBox = Me.FindControl("XTextBox12")
        If pat_dept.text <> "" Then
            keyDataList.add(New keydata("病人科室", pat_dept.text))
        End If
        '床号
        Dim pat_bed As XTextBox = Me.FindControl("XTextBox13")
        If pat_bed.text <> "" Then
            keyDataList.add(New keydata("病人床号", pat_bed.text))
        End If
        '住院号
        Dim pat_inp As XTextBox = Me.FindControl("XTextBox14")
        If pat_inp.text <> "" Then
            keyDataList.add(New keydata("病人住院号", pat_inp.text))
        End If
        '姓名
        Dim pat_name As XTextBox = Me.FindControl("XTextBox17")
        If pat_name.text <> "" Then
            keyDataList.add(New keydata("病人姓名", pat_name.text))
        End If
        '诊断
        Dim pat_dis As XTextBox = Me.FindControl("XTextBox18")
        If pat_dis.text <> "" Then
            keyDataList.add(New keydata("病人诊断", pat_dis.text))
        End If

        Dim shenqing1 As XTextBox = Me.FindControl("XTextBox19")
        If shenqing1.text <> "" Then
            keyDataList.add(New keydata("申请时间", shenqing.value))
        End If

        Dim hushizhang As XTextBox = Me.FindControl("XTextBox6")
        If hushizhang IsNot Nothing Then
            keyDataList.add(New keydata("护士长", hushizhang.text))
        End If

        '    Dim hushizhangshenhe As XDateTime = CType(Me.FindControl("XDateTime1"),XDateTime)
        Dim hushizhangshenhe As Date = Date.MinValue 'date.Parse(Me.GetControlText("XTextBox1")）
        If Me.GetControlText("XTextBox1") <> "" Then
            hushizhangshenhe = Date.Parse(Me.GetControlText("XTextBox1"))
            '    	hushizhangshenhe=Me.GetControlText("XTextBox1")
        End If
        Dim hushizhang1 As XTextBox = Me.FindControl("XTextBox6")
        If hushizhang1.text <> "" Then
            keyDataList.add(New keydata("护士长审核时间", hushizhangshenhe))
        End If
        Dim hulibu As XTextBox = Me.FindControl("XTextBox7")
        If hulibu IsNot Nothing Then
            keyDataList.add(New keydata("护理部审核人", hulibu.text))
        End If

        '    Dim hulibushenhe As XDateTime = CType(Me.FindControl("XDateTime2"),XDateTime)
        Dim hulibushenhe As Date = Date.MinValue 'date.Parse(Me.GetControlText("XTextBox11")）
        If Me.GetControlText("XTextBox11") <> "" Then
            hulibushenhe = Date.Parse(Me.GetControlText("XTextBox11"))
        End If
        Dim hulibu2 As XTextBox = Me.FindControl("XTextBox7")
        If hulibu2.text <> "" Then
            keyDataList.add(New keydata("护理部审核时间", hulibushenhe))
        End If
        Dim BradenValue As XTextBox = Me.FindControl("XTextBox20")
        If BradenValue IsNot Nothing Then
            keyDataList.add(New keydata("Braden分值", BradenValue.text))
        End If

        Dim ChuYuan As XCheckBox = Me.FindControl("XCheckBox14")
        Dim Bukebimian As XCheckBox = Me.FindControl("XCheckBox61")
        Dim NewYc As XRadioButton = Me.FindControl("XRadioButton13")
        If ChuYuan.Checked AndAlso Bukebimian.Checked AndAlso NewYc.Checked Then
            keyDataList.add(New keydata("出院状态", "发生压疮"))
        End If
        '    Dim CheckBox As Control= Me.GetCheckBoxButton("XGroupBox8")
        '    If CheckBox IsNot Nothing AndAlso CType(CheckBox,XCheckBox) IsNot Nothing Then
        '        keyDataList.add(New keydata("ReportType", CType(CheckBox,XCheckBox).Text))
        '   End If

        keyDataList.add(New keydata("ReportType", GetCheckBoxButtonText("XGroupBox8")))
        keyDataList.add(New keydata("BodyPart", Me.GetBodyPartData()))
        keyDataList.add(New keydata("Result", Me.GetResult()))
        If Me.IsZhuanGui = True Then
            keyDataList.add(New keydata("护理结果", Me.GetHuliResult()))
            Me.IsZhuanGui = False
        End If
        '保存 转科转归的 最后一次转入科室
        Dim XDataGrid6 As Xdatagrid = CType(Me.FindControl("XDataGrid6"), XDataGrid)
        If XDataGrid6.rows.count > 0 Then
            Dim sz转入科室 As String = XDataGrid6.Rows(XdataGrid6.rows.count - 1).Cells(1).Value.tostring()
            If sz转入科室 <> "" Then
                keyDataList.add(New keydata("转入科室", sz转入科室))
            End If
        End If
        Return keyDataList
    End Function

    Dim StrName As String
    '更新表单中指定的数据
    Public Overrides Function UpdateFormData(ByVal param As String, ByVal data As Object) As Boolean
        Me.RefresheTime()
        If data IsNot Nothing Then
            StrName = data
            If Not StrName.Contains("-") Then
                'Me.SetControlText("XTextBox20",split(data,";")(0) & "分")
            End If
        End If
        Return True
    End Function

    '检查转归中的表单中指定的数据
    Public Function CheckZhuanGuiResult() As Boolean
        Dim ChuYuan As XCheckBox = Me.FindControl("XCheckBox14")
        ' Dim ZhuanKe As XCheckBox = Me.FindControl("XCheckBox60")

        Dim strMsg As New StringBuilder
        If ChuYuan.checked = True Then
            Dim ChuYuanYc As XRadioButton = Me.FindControl("XRadioButton11")
            If ChuYuanYc.checked = True Then
                Dim gridView5 As XDataGrid = Me.FindControl("XDataGrid5")
                gridView5.endedit()
                If gridView5.rows.count < 2 Then
                    showmessage("压疮护理列表不为空")
                    Return False
                End If
                For item As Integer = 0 To gridView5.rows.count - 2
                    Dim row As DataGridViewRow = gridView5.rows(item)
                    If row.Cells(0).value Is Nothing OrElse row.Cells(0).value.trim() = "" Then
                        strMsg.Append("第" & item + 1 & "行部位列；")
                    End If
                    If row.Cells(3).value Is Nothing OrElse row.Cells(3).value.trim() = "" Then
                        strMsg.Append("第" & item + 1 & "行护理结果列；")
                    End If
                Next
            End If
        End If
        '    if ZhuanKe.checked = true then
        '       Dim ZhuanKeYc As XRadioButton = Me.FindControl("XRadioButton22")
        '       if ZhuanKeYc.checked = true then   
        '           Dim gridView8 As XDataGrid = Me.FindControl("XDataGrid8")
        '           gridView8.endedit()
        '           if gridView8.rows.count < 2 then
        '               showmessage("压疮护理列表不为空")
        '               return false
        '           end if
        '           for item As integer =0 to gridView8.rows.count - 2 
        '           Dim row As DataGridViewRow = gridView8.rows(item)
        '           if row.Cells(0).value is nothing OrElse row.Cells(0).value.trim() = "" then
        '              strMsg.Append("第" & item+1 & "行部位列；")
        '           end if
        '           if row.Cells(3).value is nothing OrElse row.Cells(3).value.trim() = "" then
        '              strMsg.Append("第" & item+1 & "行护理结果列；")
        '           end if
        '           next
        '       end if
        '    end if 
        If strMsg.length <> 0 Then
            showmessage(strMsg.tostring + " 不能为空！")
            Me.IsZhuanGui = False
            Return False
        End If
        Return True
    End Function

    '双击组件时发生。
    Private Sub XTextBox20_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim score As String = ""
        score = StrName
        If Me.showchildform("579380", "XTextBox20", score) Then

            Dim control As Control = Me.FindControl("XTextBox20")
            If control IsNot Nothing Then
                control.Text = split(score, ";")(0)
                control.Text += "分"
                ' control.Text = score

            End If

        End If
    End Sub


    '双击组件时发生。
    Private Sub XTextBox21_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim score As String = ""
        score = StrName
        If Me.showchildform("579380", "XTextBox21", score) Then

            Dim control As Control = Me.FindControl("XTextBox21")
            If control IsNot Nothing Then
                control.Text = split(score, ";")(0)
                control.Text += "分"
                ' control.Text = score

            End If

        End If
    End Sub

    '双击组件时发生。
    Private Sub XTextBox24_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim score As String = ""
        score = StrName
        If Me.showchildform("579380", "XTextBox24", score) Then

            Dim control As Control = Me.FindControl("XTextBox24")
            If control IsNot Nothing Then
                control.Text = split(score, ";")(0)
                control.Text += "分"
                ' control.Text = score

            End If

        End If
    End Sub

    '压疮按钮1
    Private Sub XButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim table As String = ""
        Me.showchildForm("440773", "button1", table)
    End Sub
    '压疮按钮2
    Private Sub XButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim table As String = ""
        Me.showchildForm("440773", "button2", table)
    End Sub

    Private b_submit As Boolean = False
    Private b_return As Boolean = False
    '获取表单中指定的数据
    Public Overrides Function GetFormData(ByVal param As Object) As Object
        If param = "是否显示按钮1" Then
            Return b_submit
        End If
        If param = "是否显示按钮2" Then
            Return b_return
        End If

        '去除24小时不可修订的权限控制2013-5-2
        If param = "表单权限" Then
            Return True
        End If


        '    If param = "表单摘要" Then
        '        Return Me.GetFormSummary()
        '    End If
        '    Return Nothing
        Return Me.GetFormSummary()

    End Function


    '获取表单摘要数据
    Public Function GetFormSummary() As String
        Dim StrText As New StringBuilder

        If Me.IsCheckButtonChecked("XCheckBox2") Then

            Dim gridView As XDataGrid = CType(Me.FindControl("XDataGrid1"), XDataGrid)
            For item As Integer = 0 To gridView.rows.count - 2

                Dim row As DataGridViewRow = gridView.rows(item)
                If row.Cells(0).value IsNot Nothing Then
                    StrText.Append(row.Cells(0).value & ",")
                End If
                If row.Cells(1).value IsNot Nothing Then
                    StrText.Append(row.Cells(1).value & ",")
                End If
                If row.Cells(2).value IsNot Nothing AndAlso row.Cells(2).value.trim() <> "" Then
                    StrText.Append(row.Cells(2).value & "。")

                End If
            Next
        End If

        If Me.IsCheckButtonChecked("XCheckBox1") Then

            Dim gridView1 As XDataGrid = CType(Me.FindControl("XDataGrid4"), XDataGrid)
            For item As Integer = 0 To gridView1.rows.count - 2
                Dim row As DataGridViewRow = gridView1.rows(item)
                If row.Cells(0).value IsNot Nothing Then
                    StrText.Append(row.Cells(0).value & ",")
                End If
                If row.Cells(1).value IsNot Nothing Then
                    StrText.Append(row.Cells(1).value & ",")
                End If
                If row.Cells(2).value IsNot Nothing AndAlso row.Cells(2).value.trim() <> "" Then
                    StrText.Append(row.Cells(2).value & "。")
                End If

            Next
        End If
        If Me.IsCheckButtonChecked("XCheckBox61") Then

            Dim gridView1 As XDataGrid = CType(Me.FindControl("XDataGrid5"), XDataGrid)
            For item As Integer = 0 To gridView1.rows.count - 2
                Dim row As DataGridViewRow = gridView1.rows(item)
                If row.Cells(0).value IsNot Nothing Then
                    StrText.Append(row.Cells(0).value & ",")
                End If
                If row.Cells(1).value IsNot Nothing Then
                    StrText.Append(row.Cells(1).value & ",")
                End If
                If row.Cells(2).value IsNot Nothing AndAlso row.Cells(2).value.trim() <> "" Then
                    StrText.Append(row.Cells(2).value & "。")
                End If

            Next
        End If

        If Me.IsCheckButtonChecked("XCheckBox64") Then

            Dim gridView1 As XDataGrid = CType(Me.FindControl("XDataGrid8"), XDataGrid)
            For item As Integer = 0 To gridView1.rows.count - 2
                Dim row As DataGridViewRow = gridView1.rows(item)
                If row.Cells(0).value IsNot Nothing Then
                    StrText.Append(row.Cells(0).value & ",")
                End If
                If row.Cells(1).value IsNot Nothing Then
                    StrText.Append(row.Cells(1).value & ",")
                End If
                If row.Cells(2).value IsNot Nothing AndAlso row.Cells(2).value.trim() <> "" Then
                    StrText.Append(row.Cells(2).value & "。")
                End If

            Next
        End If
        Return StrText.tostring()
    End Function


    '出院转归日期'单击组件时发生。
    Private Sub XTextBox25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim txt As XTextBox = CType(sender, XTextBox)

        Dim dtp As xdatetime = CType(Me.findcontrol("XDateTime6"), xdatetime)
        dtp.focus()
        Dim time As Date = Date.now
        dtp.Value = time.toShortDatestring()
        dtp.DroppedDown = True
    End Sub
    Private Sub XDateTime6_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim dtp As xdatetime = CType(Me.findcontrol("XDateTime6"), xdatetime)
        Me.SetControlText("XTextBox25", dtp.value.tostring("yyyy-MM-dd"))
    End Sub



    '单击组件时发生。
    Private Sub XTextBox26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim txt As XTextBox = CType(sender, XTextBox)

        Dim dtp As xdatetime = CType(Me.findcontrol("XDateTime5"), xdatetime)
        dtp.focus()
        Dim time As Date = Date.now
        dtp.Value = time.toShortDatestring()
        dtp.DroppedDown = True
    End Sub

    Private Sub XDateTime5_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim dtp As xdatetime = CType(Me.findcontrol("XDateTime5"), xdatetime)
        Me.SetControlText("XTextBox26", dtp.value.tostring("yyyy-MM-dd"))
    End Sub

    '下面两个click事件，是对日期框想为空的事情的处理
    Private Sub XTextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim txt As XTextBox = CType(sender, XTextBox)
        Dim dtp As xdatetime = CType(Me.findcontrol("XDateTime1"), xdatetime)
        dtp.focus()
        dtp.Value = DateTime.Now
        dtp.DroppedDown = True
    End Sub

    Private Sub XTextBox11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim txt As XTextBox = CType(sender, XTextBox)
        Dim dtp As xdatetime = CType(Me.findcontrol("XDateTime2"), xdatetime)
        dtp.focus()
        dtp.Value = DateTime.Now
        dtp.DroppedDown = True
    End Sub


    '单击组件时发生。
    Private Sub XTextBox23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim txt As XTextBox = CType(sender, XTextBox)
        Dim dtp As xdatetime = CType(Me.findcontrol("XDateTime4"), xdatetime)
        dtp.focus()
        dtp.Value = DateTime.Now
        dtp.DroppedDown = True
    End Sub

    '当日期时间数据改变时触发
    Private Sub XDateTime4_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim dtp As xdatetime = CType(Me.findcontrol("XDateTime4"), xdatetime)
        Me.SetControlText("XTextBox11", dtp.value.toshortDatestring())
    End Sub



    '当日期时间数据改变时触发
    Private Sub XDateTime2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim dtp As xdatetime = CType(Me.findcontrol("XDateTime2"), xdatetime)
        Me.SetControlText("XTextBox23", dtp.value.toshortDatestring())
    End Sub
    '当日期时间数据改变时触发
    Private Sub XDateTime1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim dtp As xdatetime = CType(Me.findcontrol("XDateTime1"), xdatetime)
        Me.SetControlText("XTextBox1", dtp.value.toshortDatestring())
    End Sub

    Private IsZhuanGui As Boolean = False '标志位 用于判断转归时在keylist中添加护理结果项

    Public Overrides Function SaveFormData(ByRef param As Object) As Boolean
        If param = "提交" Then
            Me.SubMitInfo()
        ElseIf param = "审核提交" Then
            Me.SubMitInfo()
        ElseIf param = "转归提交" Then
            Me.IsZhuanGui = True
            Me.SubMitInfo()
        ElseIf param = "接收" Then
            Me.SubMitInfo()
        ElseIf param = "驳回" Then
            Me.RetrunInfo()
        End If
        'showmessage(b_submit.tostring() & "/" & b_return.tostring())
        Me.RaiseCustomEvent("sender", "按钮1可见", b_submit, Nothing, Nothing)
        Me.RaiseCustomEvent("sender", "按钮2可见", b_return, Nothing, Nothing)
        Return True
    End Function

    Private Sub RetrunInfo()
        'Me.RaiseCustomEvent("sender", "保存", nothing, nothing, nothing)
        '根据申报单状态读写申报单申请信息
        Dim strPatientId As String = ""
        Me.GetSystemContext("病人ID号", strPatientId)
        Dim strVisitId As String = ""
        Me.GetSystemContext("入院次", strVisitId)

        '先读取申报单本身信息
        Dim strDocSetId As String = ""
        Me.GetSystemContext("文档集编号", strDocSetId)
        If strDocSetId = "" Then
            ShowMessage("请先保存压疮申报单！")
            Return
        End If

        '再读申报单对应的申请信息
        Dim applyData As DataSet = GetApplyByDocSetId(strDocSetId)
        If applyData Is Nothing OrElse applyData.Tables.Count <= 0 OrElse applyData.Tables(0).Rows.Count <= 0 Then
            Return
        End If
        '驳回理由
        Dim strStateMessage As String = ""
        If Not Me.ShowChildForm("230745", "tag", strStateMessage) Then
            Return
        End If
        '申报单申请状态说明：1表示已申报 2表示审核中 3表示已审核 4表示审批中 5表示已审批 6表示已转归 7表示护士长驳回 
        '8表示护理部驳回(护士长的审批) 9表示护理部驳回（“院内发生压疮”、“申报不可避免压疮”的直接申报）
        ' 调整为 6出院转归 A专科转归
        Dim strStatus As String = Me.GetFieldValue(applyData, 0, 3)
        Dim strApplyId As String = Me.GetFieldValue(applyData, 0, "apply_id")
        Select Case strStatus
            Case "2"
                '处理护士长驳回
                Me.SubmitProcess("sender", strApplyId, "7", "驳回", strStateMessage, "是否进行驳回？", "驳回确认")
            Case "4"
                '护理部驳回
                If Me.GetReportType() = 2 Then
                    Me.SubmitProcess("sender", strApplyId, "8", "驳回", strStateMessage, "是否进行驳回？", "驳回确认")
                Else
                    Me.SubmitProcess("sender", strApplyId, "9", "驳回", strStateMessage, "是否进行驳回？", "驳回确认")
                End If
            Case "8"
                Me.SubmitProcess("sender", strApplyId, "7", "驳回", strStateMessage, "是否进行驳回？", "驳回确认")
        End Select
    End Sub

    Private Sub SubmitProcess(ByVal sender As System.Object, ByVal strApplyId As String, ByVal strState As String, ByVal strStatusDesc As String, ByVal strStatusMessage As String, ByVal strMessage As String, ByVal strMessageTitle As String)
        Dim Response As Object = MsgBox(strMessage, vbYesNo, strMessageTitle)
        If Response = vbYes Then   ' 用户按下“是”。
            Me.SaveApply("sender", False, strApplyId, "压疮申报", "0", "", "", "", "", strState, strStatusDesc, strStatusMessage)

            Me.SubmitBtnTextControl()
            If strState = "2" Then '护士长接收自动填写
                Dim userName As String = ""
                Me.GetSystemContext("用户姓名", userName)
                Me.SetControlText("XTextBox6", userName)
                Dim time As Date = Date.now

                Dim XTextBox1 As XTextBox = Me.FindControl("XTextBox1")
                XTextBox1.text = time.toShortDatestring()
            ElseIf strState = "4" Then '护理部接收自动填写
                Dim userName As String = ""
                Me.GetSystemContext("用户姓名", userName)
                Me.SetControlText("XTextBox7", userName)
                Dim time As Date = Date.now
                Dim XTextBox11 As XTextBox = Me.FindControl("XTextBox11")
                XTextBox11.text = time.toShortDatestring()
            End If

            If strState = "7" Then
                Me.SetControlText("XTextBox1", "")
                Me.SetControlText("XTextBox6", "")
            ElseIf strState = "8" OrElse strState = "9" Then
                Me.SetControlText("XTextBox11", "")
                Me.SetControlText("XTextBox7", "")
            End If
            Me.RaiseCustomEvent("sender", "保存", Nothing, Nothing, Nothing)
        End If
        ' Me.RaiseCustomEvent("sender", "保存", nothing, nothing, nothing)
    End Sub



    Private Sub SubMitInfo()
        If Not CheckForm() Then
            Return
        End If
        '根据申报单状态读写申报单申请信息
        Dim strPatientId As String = ""
        Me.GetSystemContext("病人ID号", strPatientId)
        Dim strVisitId As String = ""
        Me.GetSystemContext("入院次", strVisitId)


        Dim strDocState As String = ""
        Me.GetSystemContext("病历状态", strDocState)

        '先读取申报单本身信息
        Dim strDocSetId As String = ""
        Me.GetSystemContext("文档集编号", strDocSetId)
        If strDocSetId = "" Then
            ShowMessage("请先保存压疮申报单！")
            Return
        End If

        '判断是新增
        If strDocState = "新建" Then
            '新增申报单对应的申请信息,如果申报类型为“院外带入压疮”、“高危备案”则需要先走护士长审核，然后再到护理部审核；
            '如果申报类型为“院内发生压疮”、“申报不可避免压疮”则直接到护理部审核,所以状态为3,但状态显示为“已申报”

            Dim Tijiao As Object = MsgBox("提交后不能修改，是否进行提交", vbYesNo, "提交确认")
            If Tijiao = vbYes Then
                If Me.GetReportType() = 2 Then
                    Me.SaveApply("sender", True, "", "压疮申报", "0", "", "", "", "", "1", "已申报", "")
                Else
                    Me.SaveApply("sender", True, "", "压疮申报", "0", "", "", "", "", "3", "已申报", "")
                End If
                Me.RaiseCustomEvent("sender", "保存", Nothing, Nothing, Nothing)
                Me.SubmitBtnTextControl()
            End If
            Return
        End If
        '判断 先保存 后提交
        Dim applyData As DataSet = GetApplyByDocSetId(strDocSetId)
        If applyData Is Nothing OrElse applyData.Tables.Count <= 0 OrElse applyData.Tables(0).Rows.Count <= 0 Then
            '新增申报单对应的申请信息,如果申报类型为“院外带入压疮”、“高危备案”则需要先走护士长审核，然后再到护理部审核；
            '如果申报类型为“院内发生压疮”、“申报不可避免压疮”则直接到护理部审核,所以状态为3,但状态显示为“已申报”

            Dim Tijiao As Object = MsgBox("提交后不能修改，是否进行提交", vbYesNo, "提交确认")
            If Tijiao = vbYes Then
                If Me.GetReportType() = 2 Then
                    Me.SaveApply("sender", True, "", "压疮申报", "0", "", "", "", "", "1", "已申报", "")
                Else
                    Me.SaveApply("sender", True, "", "压疮申报", "0", "", "", "", "", "3", "已申报", "")
                End If
                Me.RaiseCustomEvent("sender", "保存", Nothing, Nothing, Nothing)
                Me.SubmitBtnTextControl()
            End If
            Return
        End If

        Me.SubmitBtnTextControl()
        '申报单申请状态说明：1表示已申报 2表示审核中 3表示已审核 4表示审批中 5表示已审批 6表示已转归 7表示护士长驳回 
        '8表示护理部驳回(护士长的审批) 9表示护理部驳回（“院内发生压疮”、“申报不可避免压疮”的直接申报）
        '调整为 6出院转归 A专科转归
        Dim strStatus As String = Me.GetFieldValue(applyData, 0, 3)
        Dim strApplyId As String = Me.GetFieldValue(applyData, 0, "apply_id")
        ' showmessage(strStatus)
        Select Case strStatus
            Case "1"
                '处理接收
                Me.SubmitProcess("sender", strApplyId, "2", "审核中", "", "是否进行接收操作？", "接收确认")
            Case "2"
                '处理审核
                Me.SubmitProcess("sender", strApplyId, "3", "已审核", "", "提交后不能修改，是否进行审核提交？", "审核确认")
            Case "3"
                '处理护理部接收
                Me.SubmitProcess("sender", strApplyId, "4", "审批中", "", "是否进行接收操作？", "接收确认")
            Case "4"
                '处理审批
                Me.SubmitProcess("sender", strApplyId, "5", "已审批", "", "是否进行审批提交？", "审批确认")
            Case "5"

                '进行转科转归提交
                If Me.IsCheckButtonChecked("XCheckBox60") Then
                    '   showmessage("60")
                    Me.SubmitProcess("sender", strApplyId, "A", "已转科转归", "", "是否进行转科转归提交？", "转科转归确认")
                End If
                If Me.CheckZhuanGuiResult() = True AndAlso Me.IsCheckButtonChecked("XCheckBox14") Then
                    Me.SubmitProcess("sender", strApplyId, "6", "已出院转归", "", "是否进行出院转归提交？", "出院转归确认")
                End If
            Case "6"
            Case "A"
                If Me.IsCheckButtonChecked("XCheckBox14") Then
                    Me.SubmitProcess("sender", strApplyId, "6", "已出院转归", "", "是否进行出院转归提交？", "出院转归确认")
                End If
            Case "7"
                '处理重新申报
                Me.SubmitProcess("sender", strApplyId, "1", "已申报", "", "是否重新申报提交？", "提交确认")
            Case "8"
                '处理重新审核提交
                Me.SubmitProcess("sender", strApplyId, "3", "已审核", "", "是否重新审核提交？", "审核确认")
            Case "9"
                '处理重新提交
                Me.SubmitProcess("sender", strApplyId, "3", "已申报", "", "是否重新申报提交？", "提交确认")
        End Select
    End Sub

    Private Function GetApplyByDocSetId(ByVal strDocSetId As String) As DataSet
        Dim applySql As New StringBuilder
        applySql.Append("select apply_type,apply_name,urgency,nur_apply_index.status,patient_id,")
        applySql.Append(" patient_name,visit_id,sub_id,ward_code,ward_name,")
        applySql.Append(" applicant_id,applicant_name,apply_time,modifier_id,")
        applySql.Append(" modifier_name,modify_time,operator_id,operator_name,")
        applySql.Append(" operate_time,status_desc,next_operator_id,")
        applySql.Append(" next_operator_name,next_operator_ward_code,next_operator_ward_name,nur_apply_index.apply_id")
        applySql.Append(" from nur_apply_index join nur_apply_status ")
        applySql.Append(" on nur_apply_index.apply_id= nur_apply_status.apply_id ")
        applySql.Append(" and nur_apply_index.status= nur_apply_status.status ")
        applySql.AppendFormat(" where nur_apply_index.doc_id='{0}' order by nur_apply_status.operate_time desc ", strDocSetId)
        '    showmessage(applySql.tostring)
        Dim data As DataSet = Nothing
        Me.ExecuteQuery(applySql.ToString(), data)
        Return data
    End Function
    '保存或更新申报单申请信息
    Private Sub SaveApply(ByVal sender As System.Object, ByVal bIsNew As Boolean, ByVal strApplyID As String, ByVal strApplyType As String, ByVal strUrgency As String, ByVal strNextOperatorID As String, ByVal strNextOperatorName As String, ByVal strNextOperatorWardCode As String, ByVal strNextOperatorWardName As String, ByVal strState As String, ByVal strStatusDesc As String, ByVal strStatusMessage As String)
        '申报单申请状态说明：1表示已申报 2表示审核中 3表示已审核 4表示审批中 5表示已审批 6表示已转归 7表示护士长驳回 
        '8表示护理部驳回(护士长的审批) 9表示护理部驳回（“院内发生压疮”、“申报不可避免压疮”的直接申报）
        ' 调整为 6出院转归 A专科转归
        '接口对接参数不允许删除
        '--------------------------------------
        Dim szApplyID As String = strApplyID
        Dim szApplyType As String = strApplyType
        Dim szUrgency As String = strUrgency
        Dim szNextOperatorID As String = strNextOperatorID
        Dim szNextOperatorName As String = strNextOperatorName
        Dim szNextOperatorWardCode As String = strNextOperatorWardCode
        Dim szNextOperatorWardName As String = strNextOperatorWardName
        Dim szStatus As String = strState
        Dim szStatusDesc As String = strStatusDesc
        Dim szStatusMessage As String = strStatusMessage
        '--------------------------------------
        Dim strData As String = ""
        strData = szApplyID + ";" + szApplyType + ";" + szUrgency + ";" + szNextOperatorID + ";" + szNextOperatorName + ";" + szNextOperatorWardCode + ";" + szNextOperatorWardName + ";" + szStatus + ";" + szStatusDesc + ";" + szStatusMessage
        If bIsNew Then
            Me.RaiseCustomEvent(sender, "保存护理申请信息", Nothing, strData, Nothing)
        Else
            Me.RaiseCustomEvent(sender, "更新护理申请信息", Nothing, strData, Nothing)
        End If
    End Sub
    Private Function GetApplyStatus(ByVal strApplyId As String, ByVal strState As String) As DataSet
        Dim applySql As New StringBuilder
        applySql.Append("select operator_id,operator_name,operate_time,")
        applySql.Append(" status_desc,next_operator_id,")
        applySql.Append(" next_operator_name,next_operator_ward_code,next_operator_ward_name")
        applySql.Append(" from nur_apply_status ")
        applySql.AppendFormat(" where nur_apply_status.apply_id='{0}' and nur_apply_status.status='{1}'", strApplyId, strState)
        applySql.Append(" order by  nur_apply_status.operate_time desc ")
        Dim data As DataSet = Nothing
        Me.ExecuteQuery(applySql.ToString(), data)
        Return data
    End Function

    Private Sub SubmitBtnTextControl()

        Dim strPatientId As String = ""
        Me.GetSystemContext("病人ID号", strPatientId)
        Dim strVisitId As String = ""
        Me.GetSystemContext("入院次", strVisitId)
        Dim strUserId As Object = ""
        Me.GetSystemContext("用户编号", strUserId)
        '权限设定
        Dim UserPermiss As String = ""
        Me.GetSystemContext("用户权限_主管护师", UserPermiss)
        Dim bzhuguan As Boolean = UserPermiss = "True"
        Me.GetSystemContext("用户权限_主任护师", UserPermiss)
        Dim bzhuren As Boolean = UserPermiss = "True"
        Me.GetSystemContext("用户权限_护理部", UserPermiss)
        Dim bHuli As Boolean = UserPermiss = "True"

        b_submit = True
        Me.RaiseCustomEvent("sender", "按钮1可见", b_submit, Nothing, Nothing)
        Me.RaiseCustomEvent("sender", "按钮2可见", b_return, Nothing, Nothing)

        Me.RaiseCustomEvent("sender", "按钮1名称", "提交", Nothing, Nothing)
        Dim XGroupBox4 As XGroupBox = CType(Me.Findcontrol("XGroupBox4"), XGroupBox)
        Dim XGroupBox5 As XGroupBox = CType(Me.Findcontrol("XGroupBox5"), XGroupBox)
        Dim XGroupBox6 As XGroupBox = CType(Me.Findcontrol("XGroupBox6"), XGroupBox)
        Dim XGroupBox7 As XGroupBox = CType(Me.Findcontrol("XGroupBox7"), XGroupBox)
        Dim XGroupBox3 As XGroupBox = CType(Me.Findcontrol("XGroupBox3"), XGroupBox)
        '先读取申报单本身信息
        Dim strDocSetId As String = ""
        Me.GetSystemContext("文档集编号", strDocSetId)

        If strDocSetId = "" Then
            Return
        End If
        '再读申报单对应的申请信息
        Dim applyData As DataSet = Me.GetApplyByDocSetId(strDocSetId)
        If applyData Is Nothing OrElse applyData.Tables.Count <= 0 OrElse applyData.Tables(0).Rows.Count <= 0 Then
            PanelEnableControl(True)
            Return
        End If

        '申报单申请状态说明：1表示已申报 2表示审核中 3表示已审核 4表示审批中 5表示已审批 6表示已转归 7表示护士长驳回 
        '8表示护理部驳回(护士长的审批) 9表示护理部驳回（“院内发生压疮”、“申报不可避免压疮”的直接申报）
        ' 调整为 6出院转归 A专科转归

        Dim strStatus As String = Me.GetFieldValue(applyData, 0, 3)
        Dim strApplyId As String = Me.GetFieldValue(applyData, 0, "apply_id")
        Dim strOperatorId As String = Me.GetFieldValue(applyData, 0, "operator_id")
        Dim strApplicantId As String = Me.GetFieldValue(applyData, 0, "applicant_id")

        Select Case strStatus
            Case "1"
                PanelEnableControl(False)
                XGroupBox5.Enabled = False
                XGroupBox6.Enabled = False
                XGroupBox3.Enabled = False
                Me.RaiseCustomEvent("sender", "按钮1名称", "接收", Nothing, Nothing)
                '    If strOperatorId=strUserId Then
                ''    showmessage(strOperatorId &"=" & strUserId)
                '       b_submit=false
                '       b_return=false
                '    Else
                '      if bzhuguan orelse bzhuren then
                '       b_submit=true
                '      else
                '       b_submit=false
                '      end if
                '    End If
                If bzhuguan OrElse bzhuren Then
                    b_submit = True
                Else
                    b_submit = False
                End If
            Case "2"
                PanelEnableControl(False)
                XGroupBox5.Enabled = False
                XGroupBox6.Enabled = False
                XGroupBox3.Enabled = False

                If strOperatorId = strUserId Then
                    Me.RaiseCustomEvent("sender", "按钮1名称", "审核提交", Nothing, Nothing)
                    Me.RaiseCustomEvent("sender", "按钮2名称", "驳回", Nothing, Nothing)
                    b_return = True
                    b_submit = True
                    XGroupBox5.Enabled = True
                Else
                    b_submit = False
                End If

            Case "3"
                PanelEnableControl(False)
                XGroupBox5.Enabled = False
                XGroupBox6.Enabled = False
                XGroupBox3.Enabled = False
                If strOperatorId = strUserId Then
                    b_submit = False
                    b_return = False
                Else
                    If bhuli Then
                        b_submit = True
                    Else
                        b_submit = False
                    End If
                End If
                Me.RaiseCustomEvent("sender", "按钮1名称", "接收", Nothing, Nothing)

            Case "4"
                PanelEnableControl(False)
                XGroupBox5.Enabled = False
                XGroupBox6.Enabled = False
                XGroupBox3.Enabled = False
                If strOperatorId = strUserId Then
                    Me.RaiseCustomEvent("sender", "按钮1名称", "审核提交", Nothing, Nothing)
                    Me.RaiseCustomEvent("sender", "按钮2名称", "驳回", Nothing, Nothing)
                    b_return = True
                    XGroupBox6.Enabled = True
                Else
                    b_submit = False
                End If

            Case "5"
                PanelEnableControl(False)
                XGroupBox3.Enabled = True
                XGroupBox5.Enabled = False
                XGroupBox6.Enabled = False
                XGroupBox7.Enabled = True
                Me.RaiseCustomEvent("sender", "按钮1名称", "转归提交", Nothing, Nothing)
                b_return = False
            Case "A"
                Dim XCheckBox60 As XCheckBox = CType(Me.FindControl("XCheckBox60"), XCheckBox)
                XCheckBox60.Enabled = False
                PanelEnableControl(False)
                XGroupBox3.Enabled = True
                XGroupBox5.Enabled = False
                XGroupBox6.Enabled = False
                XGroupBox7.Enabled = True
                XGroupBox4.Enabled = False
                Me.RaiseCustomEvent("sender", "按钮1名称", "转归提交", Nothing, Nothing)
                b_return = False
            Case "6"
                PanelEnableControl(False)
                XGroupBox5.Enabled = False
                XGroupBox6.Enabled = False
                XGroupBox3.Enabled = False
                XGroupBox4.Enabled = False
                b_submit = False

            Case "7", "9"
                PanelEnableControl(False)
                XGroupBox5.Enabled = False
                XGroupBox6.Enabled = False
                XGroupBox3.Enabled = False
                Me.RaiseCustomEvent("sender", "按钮1名称", "提交", Nothing, Nothing)
                If strApplicantId <> strUserId Then
                    b_submit = False
                    b_return = False
                Else
                    b_submit = True
                    PanelEnableControl(True)
                End If

            Case "8"
                '获取上次审核提交操作人
                PanelEnableControl(False)
                XGroupBox5.Enabled = False
                XGroupBox6.Enabled = False
                XGroupBox3.Enabled = False
                Dim strLastCheckedId As String = Me.GetFieldValue(applyData, 0, "operator_id")
                Me.RaiseCustomEvent("sender", "按钮1名称", "审核提交", Nothing, Nothing)
                Me.RaiseCustomEvent("sender", "按钮2名称", "驳回", Nothing, Nothing)
                If strLastCheckedId <> strUserId Then
                    If bzhuguan OrElse bzhuren Then
                        b_submit = True
                        b_return = True
                        XGroupBox5.Enabled = True
                    Else
                        b_submit = False
                        b_return = False
                    End If
                Else
                    b_submit = False
                    b_return = False
                End If
        End Select
        '    showmessage(b_submit.tostring() & "?" & b_return.tostring())
        Me.RaiseCustomEvent("sender", "按钮1可见", b_submit, Nothing, Nothing)
        Me.RaiseCustomEvent("sender", "按钮2可见", b_return, Nothing, Nothing)
    End Sub

    Private Sub PanelEnableControl(ByVal bEnabled As Boolean)
        Dim XGroupBox8 As XGroupBox = CType(Me.Findcontrol("XGroupBox8"), XGroupBox)
        Dim XPanel13 As XPanel = CType(Me.Findcontrol("XPanel13"), XPanel)
        Dim XGroupBox9 As XGroupBox = CType(Me.Findcontrol("XGroupBox9"), XGroupBox)
        Dim XPanel16 As XPanel = CType(Me.Findcontrol("XPanel16"), XPanel)
        Dim XPanel1 As XPanel = CType(Me.Findcontrol("XPanel1"), XPanel)
        Dim XPanel15 As XPanel = CType(Me.Findcontrol("XPanel15"), XPanel)
        Dim XGroupBox5 As XGroupBox = CType(Me.Findcontrol("XGroupBox5"), XGroupBox)
        Dim XGroupBox6 As XGroupBox = CType(Me.Findcontrol("XGroupBox6"), XGroupBox)
        Dim XGroupBox7 As XGroupBox = CType(Me.Findcontrol("XGroupBox7"), XGroupBox)
        XGroupBox8.Enabled = bEnabled
        XPanel13.Enabled = bEnabled
        XGroupBox9.Enabled = bEnabled
        XPanel16.Enabled = bEnabled
        XPanel1.Enabled = bEnabled
        XPanel15.Enabled = bEnabled
        If bEnabled = True Then
            XGroupBox5.Enabled = False
            XGroupBox6.Enabled = False
        Else
            XGroupBox5.Enabled = True
            XGroupBox6.Enabled = True
        End If
        XGroupBox7.Enabled = bEnabled
    End Sub

    Private Function GetReportType() As Integer
        Dim returnValue As Integer = 2
        '  '返回1表示直接护理部审批，返回2表示需要先走护士长审批，然后再走护理部审批
        '   Dim radioButton As Control= Me.GetCheckedButton("XGroupBox8")
        '   Dim strReportType As String=""
        '   If radioButton IsNot Nothing AndAlso CType(radioButton,XRadioButton) IsNot Nothing Then
        '      strReportType=CType(radioButton,XRadioButton).Text
        '   End If
        '   Dim XCheckBox1 As XCheckBox=CType(Me.Findcontrol("XCheckBox1"), XCheckBox)
        '   Dim XCheckBox4 As XCheckBox=CType(Me.Findcontrol("XCheckBox4"), XCheckBox)
        ''   showmessage(strReportType)
        '   If strReportType="院外带入压疮" OrElse strReportType="高危备案" OrElse XCheckBox1.checked=true OrElse XCheckBox1.checked=true Then
        '      returnValue= 2
        '   Else 
        '      returnValue= 1
        '   End If
        Return returnValue
    End Function

    Private Function GetCheckedButton(ByVal parentName As String) As Control
        Dim checked_control As control = Nothing
        Dim parent As control = Me.findcontrol(parentName)
        If parent IsNot Nothing Then
            For Each child_control As control In parent.controls
                If child_control.GetType() IsNot GetType(XRadioButton) Then
                    Continue For
                End If
                Dim radio_button As XRadioButton = CType(child_control, XRadioButton)
                If radio_button IsNot Nothing AndAlso radio_button.Checked Then
                    checked_control = radio_button
                    Exit For
                End If
            Next
        End If
        Return checked_control
    End Function
    '只返回第一个选定项
    Private Function GetCheckBoxButtonText(ByVal parentName As String) As String
        Dim strReportType As String = ""
        Dim parent As control = Me.findcontrol(parentName)
        If parent IsNot Nothing Then
            For Each child_control As control In parent.controls
                If child_control.GetType() IsNot GetType(XCheckBox) Then
                    Continue For
                End If
                Dim checkbox_button As XCheckBox = CType(child_control, XCheckBox)
                If checkbox_button IsNot Nothing AndAlso checkbox_button.Checked Then
                    If (strReportType = "") Then
                        strReportType = checkbox_button.Text
                    Else
                        strReportType = strReportType & "；" & checkbox_button.Text
                    End If
                End If
            Next
        End If
        Return strReportType
    End Function

    '获取部位、大小数据
    Public Function GetBodyPartData() As String
        Dim StrText As New StringBuilder

        Dim gridView As XDataGrid = CType(Me.FindControl("XDataGrid1"), XDataGrid)
        For item As Integer = 0 To gridView.rows.count - 2

            Dim row As DataGridViewRow = gridView.rows(item)
            If row.Cells(0).value IsNot Nothing Then
                StrText.Append(row.Cells(0).value & "，")
            End If
            If row.Cells(1).value IsNot Nothing Then
                StrText.Append(row.Cells(1).value & "，")
            End If
            If row.Cells(2).value IsNot Nothing AndAlso row.Cells(2).value.trim() <> "" Then
                StrText.Append(row.Cells(2).value & "。")

            End If
        Next


        Dim gridView1 As XDataGrid = CType(Me.FindControl("XDataGrid4"), XDataGrid)
        For item As Integer = 0 To gridView1.rows.count - 2
            Dim row As DataGridViewRow = gridView1.rows(item)
            If row.Cells(0).value IsNot Nothing Then
                StrText.Append(row.Cells(0).value & "，")
            End If
            If row.Cells(1).value IsNot Nothing Then
                StrText.Append(row.Cells(1).value & "，")
            End If
            If row.Cells(2).value IsNot Nothing AndAlso row.Cells(2).value.trim() <> "" Then
                StrText.Append(row.Cells(2).value & "。")
            End If

        Next


        Return StrText.tostring()
    End Function

    '获取转归情况
    Private Function GetResult() As String
        Dim StrText As New StringBuilder
        Dim gridView5 As XDataGrid = CType(Me.FindControl("XDataGrid5"), XDataGrid)
        For item As Integer = 0 To gridView5.rows.count - 2
            Dim row As DataGridViewRow = gridView5.rows(item)
            If row.Cells(0).value IsNot Nothing Then
                StrText.Append(row.Cells(0).value & "，")
            End If
            If row.Cells(3).value IsNot Nothing AndAlso row.Cells(3).value.trim() <> "" Then
                StrText.Append(row.Cells(3).value & "。")
            End If
        Next
        Dim gridView1 As XDataGrid = CType(Me.FindControl("XDataGrid6"), XDataGrid)
        For item As Integer = 0 To gridView1.rows.count - 2
            Dim row As DataGridViewRow = gridView1.rows(item)
            '        If row.Cells(0).value IsNot Nothing Then
            '            StrText.Append(row.Cells(0).value & "，")
            '        End If
            '        If row.Cells(3).value IsNot Nothing AndAlso row.Cells(3).value.trim() <> "" Then
            '            StrText.Append(row.Cells(3).value & "。")
            '        End If
            If row.Cells(2).value IsNot Nothing AndAlso row.Cells(2).value.trim() <> "" Then
                StrText.Append(row.Cells(2).value & "。")
            End If
        Next
        Return StrText.tostring()
    End Function

    '获取护理情况
    Public Function GetHuliResult() As String
        Dim ChuYuan As XCheckBox = Me.FindControl("XCheckBox14")
        Dim ZhuanKe As XCheckBox = Me.FindControl("XCheckBox60")
        Dim ChuYuanYc As XRadioButton = Me.FindControl("XRadioButton11")
        Dim ZhuanKeYc As XRadioButton = Me.FindControl("XRadioButton22")
        Dim gridView5 As XDataGrid = Me.FindControl("XDataGrid5")
        Dim gridView8 As XDataGrid = Me.FindControl("XDataGrid6")

        Dim strMsg As New StringBuilder
        If ChuYuan.checked = True And ChuYuanYc.checked = True Then
            For item As Integer = 0 To gridView5.rows.count - 2
                Dim row As DataGridViewRow = gridView5.rows(item)
                If row.Cells(0).value IsNot Nothing AndAlso row.Cells(0).value.trim() <> "" AndAlso row.Cells(3).value IsNot Nothing AndAlso row.Cells(3).value.trim() <> "" Then
                    strMsg.Append(row.Cells(0).value & "，" & row.Cells(3).value & "。")
                End If
            Next
        End If
        If ZhuanKe.checked = True Then
            For item As Integer = 0 To gridView8.rows.count - 2
                Dim row As DataGridViewRow = gridView8.rows(item)
                If row.Cells(5).value IsNot Nothing AndAlso row.Cells(5).value.trim() <> "" Then
                    strMsg.Append(row.Cells(5).value + "。")
                End If
            Next
        End If
        '    showmessage(strMsg.tostring())
        Return strMsg.tostring()
    End Function
    Public Function CheckForm() As Boolean
        Dim message As New StringBuilder
        '申报类型
        If Not IsRadioButtonChecked("XRadioButton7") And Not IsRadioButtonChecked("XRadioButton8") _
        And Not IsRadioButtonChecked("XRadioButton9") And Not IsRadioButtonChecked("XRadioButton10") _
        And Not IsCheckButtonChecked("XCheckBox1") And Not IsCheckButtonChecked("XCheckBox2") _
        And Not IsCheckButtonChecked("XCheckBox3") And Not IsCheckButtonChecked("XCheckBox4") Then
            message.AppendLine("申报类型")
        End If
        'braden分值
        If Not (Me.GetControlText("XTextBox20").trim() <> "" Or Me.GetControlText("XTextBox21").trim() <> "" _
        Or Me.GetControlText("XTextBox24").trim() <> "") Then
            message.AppendLine("Braden 分值")
        End If
        '如申报压疮则压疮情况必填
        Dim XDataGrid4 As XDataGrid = Me.FindControl("XDataGrid4")
        If (IsRadioButtonChecked("XRadioButton7") Or IsCheckButtonChecked("XCheckBox1")) And XDataGrid4.rows(0).cells(0).value = "" Then
            message.AppendLine("压疮发生情况")
        End If

        Dim XDataGrid1 As XDataGrid = Me.FindControl("XDataGrid1")
        If (IsRadioButtonChecked("XRadioButton8") Or IsCheckButtonChecked("XCheckBox")) And XDataGrid1.rows(0).cells(0).value = "" Then '
            message.AppendLine("压疮发生情况")
        End If
        '申报不可避免则基本条件与附加条件必填
        '    showmessage(IsRadioButtonChecked("XRadioButton9").tostring()+ IsCheckButtonChecked("XCheckBox5").tostring()+IsCheckButtonChecked("XCheckBox6").tostring()+IsCheckButtonChecked("XCheckBox7").tostring()+IsCheckButtonChecked("XCheckBox8").tostring()+IsCheckButtonChecked("XCheckBox9").tostring())
        If (IsRadioButtonChecked("XRadioButton9") Or IsCheckButtonChecked("XCheckBox3")) And Not (IsCheckButtonChecked("XCheckBox5") Or _
        IsCheckButtonChecked("XCheckBox6") Or IsCheckButtonChecked("XCheckBox7") Or IsCheckButtonChecked("XCheckBox74") Or _
        IsCheckButtonChecked("XCheckBox8") Or IsCheckButtonChecked("XCheckBox9")) Then
            message.AppendLine("基本条件")
        End If

        If (IsCheckButtonChecked("XCheckBox3") Or IsRadioButtonChecked("XRadioButton9")) And Not (IsCheckButtonChecked("XCheckBox10") Or _
         IsCheckButtonChecked("XCheckBox11") Or IsCheckButtonChecked("XCheckBox79") Or _
         IsCheckButtonChecked("XCheckBox80")) Then
            message.AppendLine("附加条件")
        End If

        Dim strDocSetId As String = ""
        Me.GetSystemContext("文档集编号", strDocSetId)
        If strDocSetId <> "" Then
            Dim applyData As DataSet = GetApplyByDocSetId(strDocSetId)
            Dim strStatus As String = Me.GetFieldValue(applyData, 0, 3)
            If strStatus = "2" Then
                '护理措施是否落实
                If Not IsRadioButtonChecked("XRadioButton3") And Not IsRadioButtonChecked("XRadioButton4") _
                And Not IsRadioButtonChecked("XRadioButton5") Then
                    message.AppendLine("护理措施是否落实")
                End If
                '审核类型
                If IsCheckButtonChecked("XCheckBox49") And Not (IsCheckButtonChecked("XCheckBox52") Or _
                IsCheckButtonChecked("XCheckBox51") Or IsCheckButtonChecked("XCheckBox40") Or _
                IsCheckButtonChecked("XCheckBox41") Or IsCheckButtonChecked("XCheckBox42") Or _
                IsCheckButtonChecked("XCheckBox43") Or IsCheckButtonChecked("XCheckBox44") Or _
                IsCheckButtonChecked("XCheckBox45")) Then
                    message.AppendLine("审核结果")
                End If
                '     		if not IsCheckButtonChecked("XCheckBox49") and not((IsCheckButtonChecked("XCheckBox39") _
                '     		and Me.GetControlText("XTextBox3").trim() <> "") Or (IsCheckButtonChecked("XCheckBox38") _
                '     		and Me.GetControlText("XTextBox4").trim() <> ""))then
                '     			message.AppendLine("审核结果")
                '     		end if
            End If
            If strStatus = "4" Then
                '护理措施是否落实
                If Not IsRadioButtonChecked("XRadioButton6") And Not IsRadioButtonChecked("XRadioButton2") _
                And Not IsRadioButtonChecked("XRadioButton1") Then
                    message.AppendLine("护理措施是否落实")
                End If
                '审核类型
                If IsCheckButtonChecked("XCheckBox59") And Not (IsCheckButtonChecked("XCheckBox56") Or _
                IsCheckButtonChecked("XCheckBox55") Or IsCheckButtonChecked("XCheckBox54") Or _
                IsCheckButtonChecked("XCheckBox53") Or IsCheckButtonChecked("XCheckBox50") Or _
                IsCheckButtonChecked("XCheckBox48") Or IsCheckButtonChecked("XCheckBox47") Or _
                IsCheckButtonChecked("XCheckBox46")) Then
                    message.AppendLine("审核结果")
                End If
                If Not IsCheckButtonChecked("XCheckBox59") And Not ((IsCheckButtonChecked("XCheckBox58") _
                And Me.GetControlText("XTextBox10").trim() <> "") Or (IsCheckButtonChecked("XCheckBox57") _
                And Me.GetControlText("XTextBox9").trim() <> "")) Then
                    message.AppendLine("审核结果")
                End If
            End If
        End If

        If message.Length > 0 Then
            ShowWarning("以下选项：" & message.tostring() & "尚未填写内容！")
            Return False
        End If
        Return True
    End Function


    '护士长审核 压疮类型匹配。
    Private Sub XCheckBox52_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim XCheckBox1 As XCheckBox = Me.FindControl("XCheckBox1")
        Dim XCheckBox52 As XCheckBox = Me.FindControl("XCheckBox52")

        If XCheckBox52.checked Then
            If XCheckBox1.checked = False Then
                ShowWarning("申报类型匹配错误请检查")
            End If
        End If
    End Sub


    '护士长审核 压疮类型匹配
    Private Sub XCheckBox51_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim XCheckBox51 As XCheckBox = Me.FindControl("XCheckBox51")
        Dim XCheckBox2 As XCheckBox = Me.FindControl("XCheckBox2")

        If XCheckBox51.checked Then
            If XCheckBox2.checked = False Then
                ShowWarning("申报类型匹配错误请检查")
            End If
        End If
    End Sub


    '护士长审核 每当 Check 属性更改时发生。
    Private Sub XCheckBox39_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim XCheckBox39 As XCheckBox = Me.FindControl("XCheckBox39")
        Dim XCheckBox3 As XCheckBox = Me.FindControl("XCheckBox3")
        If XCheckBox39.checked = False Then
            Dim XTextBox3 As XTextBox = Me.FindControl("XTextBox3")
            XTextBox3.text = ""
        End If

        If XCheckBox39.checked Then
            If XCheckBox3.checked = False Then
                ShowWarning("申报类型匹配错误请检查")
            End If
        End If
    End Sub


    '每当 Check 属性更改时发生。
    Private Sub XCheckBox38_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim XCheckBox38 As XCheckBox = Me.FindControl("XCheckBox38")
        Dim XCheckBox4 As XCheckBox = Me.FindControl("XCheckBox4")
        If XCheckBox38.checked = False Then
            Dim XTextBox4 As XTextBox = Me.FindControl("XTextBox4")
            XTextBox4.text = ""
        End If

        If XCheckBox38.checked Then
            If XCheckBox4.checked = False Then
                ShowWarning("申报类型匹配错误请检查")
            End If
        End If


    End Sub

    '护理部审核匹配
    Private Sub XCheckBox56_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim XCheckBox56 As XCheckBox = Me.FindControl("XCheckBox56")
        Dim XCheckBox1 As XCheckBox = Me.FindControl("XCheckBox1")

        If XCheckBox56.checked Then
            If XCheckBox1.checked = False Then
                ShowWarning("申报类型匹配错误请检查")
            End If
        End If

    End Sub


    '护理部
    Private Sub XCheckBox55_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim XCheckBox55 As XCheckBox = Me.FindControl("XCheckBox55")
        Dim XCheckBox2 As XCheckBox = Me.FindControl("XCheckBox2")

        If XCheckBox55.checked Then
            If XCheckBox2.checked = False Then
                ShowWarning("申报类型匹配错误请检查")
            End If
        End If
    End Sub



    '护理部审核3。
    Private Sub XCheckBox58_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim XCheckBox58 As XCheckBox = Me.FindControl("XCheckBox58")
        Dim XCheckBox3 As XCheckBox = Me.FindControl("XCheckBox3")
        If XCheckBox58.checked = False Then
            Dim XTextBox10 As XTextBox = Me.FindControl("XTextBox10")
            XTextBox10.text = ""
        End If

        If XCheckBox58.checked Then
            If XCheckBox3.checked = False Then
                ShowWarning("申报类型匹配错误请检查")
            End If
        End If

    End Sub

    '护理部4。
    Private Sub XCheckBox57_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim XCheckBox57 As XCheckBox = Me.FindControl("XCheckBox57")
        Dim XCheckBox4 As XCheckBox = Me.FindControl("XCheckBox4")
        If XCheckBox57.checked = False Then
            Dim XTextBox9 As XTextBox = Me.FindControl("XTextBox9")
            XTextBox9.text = ""
        End If


        If XCheckBox57.checked Then
            If XCheckBox4.checked = False Then
                ShowWarning("申报类型匹配错误请检查")
            End If
        End If
    End Sub

    '在单元格中的任意位置单击鼠标时发生。
    Private Sub XDataGrid1_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)

        If e.RowIndex >= 0 Then
            Dim gridView As XDataGrid = Me.FindControl("XDataGrid1")
            If gridView Is Nothing Then
                Exit Sub
            End If
            '这里转换为.net标准的datagraidview控件
            Dim is_new_row As Boolean = CType(gridView, datagridview).Rows(e.RowIndex).IsNewRow
            Dim formdata As Object = Nothing
            If Me.ShowChildForm("326279", "XdataGrid1" & "_Row" & e.RowIndex.ToString(), formdata) Then
                If formdata Is Nothing OrElse formdata.gettype() IsNot GetType(datatable) Then
                    Exit Sub
                End If
                If is_new_row Then
                    gridView.Rows.InsertCopy(e.RowIndex, e.RowIndex)
                End If

                Dim data As datatable = formdata

                gridView.Rows(e.RowIndex).Cells(0).Value = Me.getfieldvalue(data, 0, "部位")
                gridView.Rows(e.RowIndex).Cells(1).Value = Me.getfieldvalue(data, 0, "大小")
                gridView.Rows(e.RowIndex).Cells(2).Value = Me.getfieldvalue(data, 0, "分期")
                gridView.Rows(e.RowIndex).Cells(3).Value = Me.getfieldvalue(data, 0, "发生时间")
            End If
        End If

    End Sub


    '在单元格中的任意位置单击鼠标时发生。
    Private Sub XDataGrid4_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)
        If e.RowIndex >= 0 Then
            Dim gridView As XDataGrid = Me.FindControl("XDataGrid4")
            If gridView Is Nothing Then
                Exit Sub
            End If
            '这里转换为.net标准的datagraidview控件
            Dim is_new_row As Boolean = CType(gridView, datagridview).Rows(e.RowIndex).IsNewRow
            Dim formdata As Object = Nothing
            If Me.ShowChildForm("326279", "XDataGrid4" & "_Row" & e.RowIndex.ToString(), formdata) Then
                If formdata Is Nothing OrElse formdata.gettype() IsNot GetType(datatable) Then
                    Exit Sub
                End If
                If is_new_row Then
                    gridView.Rows.InsertCopy(e.RowIndex, e.RowIndex)
                End If

                Dim data As datatable = formdata

                gridView.Rows(e.RowIndex).Cells(0).Value = Me.getfieldvalue(data, 0, "部位")
                gridView.Rows(e.RowIndex).Cells(1).Value = Me.getfieldvalue(data, 0, "大小")
                gridView.Rows(e.RowIndex).Cells(2).Value = Me.getfieldvalue(data, 0, "分期")
            End If
        End If

    End Sub


    '在单元格中的任意位置单击鼠标时发生。
    Private Sub XDataGrid8_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)
        'if e.RowIndex >= 0 then
        If e.columnindex <= 2 AndAlso e.rowindex >= 0 Then
            Dim gridView As XDataGrid = Me.FindControl("XDataGrid8")
            If gridView Is Nothing Then
                Exit Sub
            End If
            '这里转换为.net标准的datagraidview控件
            Dim is_new_row As Boolean = CType(gridView, datagridview).Rows(e.RowIndex).IsNewRow
            Dim formdata As Object = Nothing
            If Me.ShowChildForm("326279", "XDataGrid8" & "_Row" & e.RowIndex.ToString(), formdata) Then
                If formdata Is Nothing OrElse formdata.gettype() IsNot GetType(datatable) Then
                    Exit Sub
                End If
                If is_new_row Then
                    gridView.Rows.InsertCopy(e.RowIndex, e.RowIndex)
                End If

                Dim data As datatable = formdata

                gridView.Rows(e.RowIndex).Cells(0).Value = Me.getfieldvalue(data, 0, "部位")
                gridView.Rows(e.RowIndex).Cells(1).Value = Me.getfieldvalue(data, 0, "大小")
                gridView.Rows(e.RowIndex).Cells(2).Value = Me.getfieldvalue(data, 0, "分期")
            End If
            Dim time8 As Date = Date.now
            gridView.Rows(e.RowIndex).Cells(4).Value = time8

        End If

    End Sub

    '在单元格中的任意位置单击鼠标时发生。
    Private Sub XDataGrid7_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)
        If e.RowIndex >= 0 Then
            Dim gridView As XDataGrid = Me.FindControl("XDataGrid7")
            If gridView Is Nothing Then
                Exit Sub
            End If
            '这里转换为.net标准的datagraidview控件
            Dim is_new_row As Boolean = CType(gridView, datagridview).Rows(e.RowIndex).IsNewRow
            Dim formdata As Object = Nothing
            If Me.ShowChildForm("326279", "XDataGrid7" & "_Row" & e.RowIndex.ToString(), formdata) Then
                If formdata Is Nothing OrElse formdata.gettype() IsNot GetType(datatable) Then
                    Exit Sub
                End If
                If is_new_row Then
                    gridView.Rows.InsertCopy(e.RowIndex, e.RowIndex)
                End If

                Dim data As datatable = formdata

                gridView.Rows(e.RowIndex).Cells(0).Value = Me.getfieldvalue(data, 0, "部位")
                gridView.Rows(e.RowIndex).Cells(1).Value = Me.getfieldvalue(data, 0, "大小")
                gridView.Rows(e.RowIndex).Cells(2).Value = Me.getfieldvalue(data, 0, "分期")
            End If
        End If

    End Sub


    '在单元格中的任意位置单击鼠标时发生。
    Private Sub XDataGrid6_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)

        If e.ColumnIndex < 0 OrElse e.RowIndex < 0 Then
            Exit Sub
        End If

        'Dim gridView As XDataGrid = CType(sender, XDataGrid)
        If e.ColumnIndex = 1 Then
            Me.ShowContextMenu("选择转入科室")
            rowIndex = e.RowIndex

        End If
        If e.RowIndex >= 0 AndAlso e.ColumnIndex <> 1 Then
            Dim gridView As XDataGrid = Me.FindControl("XDataGrid6")
            If gridView Is Nothing Then
                Exit Sub
            End If
            '这里转换为.net标准的datagraidview控件
            Dim is_new_row As Boolean = CType(gridView, datagridview).Rows(e.RowIndex).IsNewRow
            Dim formdata As Object = Nothing
            If Me.ShowChildForm("430863", "XDataGrid6" & "_Row" & e.RowIndex.ToString(), formdata) Then
                If formdata Is Nothing OrElse formdata.gettype() IsNot GetType(datatable) Then
                    Exit Sub
                End If
                If is_new_row Then
                    gridView.Rows.InsertCopy(e.RowIndex, e.RowIndex)
                End If

                Dim data As datatable = formdata

                gridView.Rows(e.RowIndex).Cells(2).Value = Me.getfieldvalue(data, 0, "转归情况")
                gridView.Rows(e.RowIndex).Cells(3).Value = Me.getfieldvalue(data, 0, "评估人")
                gridView.Rows(e.RowIndex).Cells(4).Value = Me.getfieldvalue(data, 0, "评估日期")
                gridView.Rows(e.RowIndex).Cells(5).Value = Me.getfieldvalue(data, 0, "护理结果")
            End If
        End If
        '  


    End Sub

    '双击 DataGridView 中的单元格时发生。
    Private Sub XDataGrid6_CellMouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)
        'e.ColumnIndex, System.Int32
        'e.RowIndex, System.Int32
        'e.Button, System.Windows.Forms.MouseButtons, 可取值为:
        'If e.Button = System.Windows.Forms.MouseButtons.None Then
        'If e.Button = System.Windows.Forms.MouseButtons.Left Then
        'If e.Button = System.Windows.Forms.MouseButtons.Right Then
        'If e.Button = System.Windows.Forms.MouseButtons.Middle Then
        'If e.Button = System.Windows.Forms.MouseButtons.XButton1 Then
        'If e.Button = System.Windows.Forms.MouseButtons.XButton2 Then

        'e.Clicks, System.Int32
        'e.X, System.Int32
        'e.Y, System.Int32
        'e.Delta, System.Int32
        'e.Location, System.Drawing.Point


    End Sub

    '单击组件时发生。
    Private Sub XButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim XDataGrid6 As XDataGrid = CType(Me.FindControl("XDataGrid6"), XDataGrid)
        Dim rowIndex As Integer = XDataGrid6.Rows.Add()
        XDataGrid6.Rows(rowIndex).Cells(0).Value = (RowIndex + 1).tostring
    End Sub



    '在单元格中的任意位置单击鼠标时发生。
    Private Sub XDataGrid5_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)
        'if e.RowIndex >= 0 then

        If e.columnindex <= 2 AndAlso e.rowindex >= 0 Then

            Dim gridView As XDataGrid = Me.FindControl("XDataGrid5")
            If gridView Is Nothing Then
                Exit Sub
            End If
            '这里转换为.net标准的datagraidview控件
            Dim is_new_row As Boolean = CType(gridView, datagridview).Rows(e.RowIndex).IsNewRow
            Dim formdata As Object = Nothing
            If Me.ShowChildForm("326279", "XDataGrid5" & "_Row" & e.RowIndex.ToString(), formdata) Then
                If formdata Is Nothing OrElse formdata.gettype() IsNot GetType(datatable) Then
                    Exit Sub
                End If
                If is_new_row Then
                    gridView.Rows.InsertCopy(e.RowIndex, e.RowIndex)
                End If

                Dim data As datatable = formdata

                gridView.Rows(e.RowIndex).Cells(0).Value = Me.getfieldvalue(data, 0, "部位")
                gridView.Rows(e.RowIndex).Cells(1).Value = Me.getfieldvalue(data, 0, "大小")
                gridView.Rows(e.RowIndex).Cells(2).Value = Me.getfieldvalue(data, 0, "分期")
            End If

            Dim time5 As Date = Date.now
            gridView.Rows(e.RowIndex).Cells(4).Value = time5


        End If

    End Sub

    '在单元格中的任意位置单击鼠标时发生。
    Private Sub XDataGrid3_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)
        If e.RowIndex >= 0 Then
            Dim gridView As XDataGrid = Me.FindControl("XDataGrid3")
            If gridView Is Nothing Then
                Exit Sub
            End If
            '这里转换为.net标准的datagraidview控件
            Dim is_new_row As Boolean = CType(gridView, datagridview).Rows(e.RowIndex).IsNewRow
            Dim formdata As Object = Nothing
            If Me.ShowChildForm("326279", "XDataGrid3" & "_Row" & e.RowIndex.ToString(), formdata) Then
                If formdata Is Nothing OrElse formdata.gettype() IsNot GetType(datatable) Then
                    Exit Sub
                End If
                If is_new_row Then
                    gridView.Rows.InsertCopy(e.RowIndex, e.RowIndex)
                End If

                Dim data As datatable = formdata

                gridView.Rows(e.RowIndex).Cells(0).Value = Me.getfieldvalue(data, 0, "部位")
                gridView.Rows(e.RowIndex).Cells(1).Value = Me.getfieldvalue(data, 0, "大小")
                gridView.Rows(e.RowIndex).Cells(2).Value = Me.getfieldvalue(data, 0, "分期")
            End If
        End If

    End Sub

    '在单元格中的任意位置单击鼠标时发生。
    Private Sub XDataGrid2_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)
        If e.RowIndex >= 0 Then
            Dim gridView As XDataGrid = Me.FindControl("XDataGrid2")
            If gridView Is Nothing Then
                Exit Sub
            End If
            '这里转换为.net标准的datagraidview控件
            Dim is_new_row As Boolean = CType(gridView, datagridview).Rows(e.RowIndex).IsNewRow
            Dim formdata As Object = Nothing
            If Me.ShowChildForm("326279", "XDataGrid2" & "_Row" & e.RowIndex.ToString(), formdata) Then
                If formdata Is Nothing OrElse formdata.gettype() IsNot GetType(datatable) Then
                    Exit Sub
                End If
                If is_new_row Then
                    gridView.Rows.InsertCopy(e.RowIndex, e.RowIndex)
                End If

                Dim data As datatable = formdata

                gridView.Rows(e.RowIndex).Cells(0).Value = Me.getfieldvalue(data, 0, "部位")
                gridView.Rows(e.RowIndex).Cells(1).Value = Me.getfieldvalue(data, 0, "大小")
                gridView.Rows(e.RowIndex).Cells(2).Value = Me.getfieldvalue(data, 0, "分期")
                gridView.Rows(e.RowIndex).Cells(3).Value = Me.getfieldvalue(data, 0, "发生时间")
            End If
        End If

    End Sub




    '每当 Check 属性更改时发生。
    Private Sub XCheckBox62_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim XCheckBox62 As XCheckBox = Me.FindControl("XCheckBox62")
        If XCheckBox62.Checked Then
            Dim table As DataTable = 获取该次入院第一次压疮申报信息()
            If table Is Nothing OrElse table.rows.count <= 0 Then
                Return
            End If
            If Not 数据是否可导入(table) Then
                Return
            End If
            填写数据(table)
        End If
    End Sub

    '每当 Check 属性更改时发生。
    Private Sub XCheckBox64_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim XCheckBox64 As XCheckBox = Me.FindControl("XCheckBox64")
        If XCheckBox64.Checked Then
            Dim table As DataTable = 获取该次入院第一次压疮申报信息()
            If table Is Nothing OrElse table.rows.count <= 0 Then
                Return
            End If
            If Not 数据是否可导入(table) Then
                Return
            End If
            填写数据2(table)
        End If
    End Sub



    Private Function 数据是否可导入(ByVal table As DataTable) As Boolean
        For index As Integer = 0 To table.Rows.Count - 1
            Dim stType As String = Me.GetFieldValue(table.rows(index), "data_value").ToString()
            If stType.Contains("院内发生压疮") Or stType.Contains("院外带入压疮") Then
                Return True
            End If
        Next index
        Return False
    End Function

    Private Sub 填写数据(ByVal table As DataTable)
        showmessage("这里1")
        Dim XDataGrid5 As XDataGrid = Me.FindControl("XDataGrid5")
        For index As Integer = 0 To table.Rows.Count - 1
            '如果是BodyPart表格数据
            If Me.GetFieldValue(table.rows(index), "data_name").ToString().Contains("BodyPart") Then
                '表格数据分解成行
                Dim szRows() As String = Nothing
                Dim timenow As DateTime = DateTime.Now
                szRows = Me.GetFieldValue(table.rows(index), "data_value").ToString().Split("。")
                XDataGrid5.Rows.Clear()
                For RowIndex As Integer = 0 To szRows.Length - 2
                    '表格数据分解成cell
                    Dim szCells() As String = Nothing
                    szCells = szRows(RowIndex).Split("，")
                    If RowIndex > 3 Then
                        Return
                    End If
                    XDataGrid5.Rows.Add()
                    showmessage("这里2")
                    Me.SetCellValue(XDataGrid5, RowIndex, 0, szCells(0))
                    Me.SetCellValue(XDataGrid5, RowIndex, 1, szCells(1))
                    Me.SetCellValue(XDataGrid5, RowIndex, 2, szCells(2))
                    Me.SetCellValue(XDataGrid5, RowIndex, 4, timenow)

                Next RowIndex
            End If
        Next index
    End Sub

    Private Sub 填写数据2(ByVal table As DataTable)
        showmessage("填写数据2")
        Dim XDataGrid5 As XDataGrid = Me.FindControl("XDataGrid8")
        For index As Integer = 0 To table.Rows.Count - 1
            '如果是BodyPart表格数据
            If Me.GetFieldValue(table.rows(index), "data_name").ToString().Contains("BodyPart") Then
                '表格数据分解成行
                Dim szRows() As String = Nothing
                Dim timenow As DateTime = DateTime.Now
                szRows = Me.GetFieldValue(table.rows(index), "data_value").ToString().Split("。")
                XDataGrid5.Rows.Clear()
                For RowIndex As Integer = 0 To szRows.Length - 2
                    '表格数据分解成cell
                    Dim szCells() As String = Nothing
                    szCells = szRows(RowIndex).Split("，")
                    If RowIndex > 3 Then
                        Return
                    End If
                    XDataGrid5.Rows.Add()
                    Me.SetCellValue(XDataGrid5, RowIndex, 0, szCells(0))
                    Me.SetCellValue(XDataGrid5, RowIndex, 1, szCells(1))
                    Me.SetCellValue(XDataGrid5, RowIndex, 2, szCells(2))
                    Me.SetCellValue(XDataGrid5, RowIndex, 4, timenow)
                Next RowIndex
            End If
        Next index
    End Sub

    Private Function 获取该次入院第一次压疮申报信息() As DataTable
        Dim strPatientId As String = "11252673"
        Me.GetSystemContext("病人ID号", strPatientId)
        Dim strVisitId As String = "1"
        Me.GetSystemContext("入院次", strVisitId)

        Dim sql As New StringBuilder()
        sql.Append("select t.data_name,t.data_value from DOC_SUMMARY_DATA t ")
        sql.Append(" where t.doc_id =(select doc_id from ")
        sql.Append(" (select t.doc_id from DOC_SUMMARY_DATA t where ")
        sql.Append(" t.doctype_id='624103' and t.patient_id='" + strPatientId + "' and t.visit_id='" + strVisitId + "' ")
        sql.Append(" and t.data_name='申请时间' order by t.data_value asc) where rownum < 2) ")
        showmessage(sql.tostring())
        Dim dataSet As New DataSet
        Me.ExecuteQuery(sql.ToString(), dataSet)
        If dataSet Is Nothing OrElse dataSet.Tables.Count <= 0 Then
            Return Nothing
        End If
        Return dataSet.Tables(0)
    End Function

    ''出院转归 压疮框自动获取
    'Private Sub XCheckBox61_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    '    Dim datagridview1 As XDataGrid = Me.FindControl("XDataGrid4")
    '    Dim datagridview2 As XDataGrid = Me.FindControl("XDataGrid5")

    '    If datagridview1.Rows.Count <= 0 Then
    '        Return
    '    End If

    '    For rowIndex As Integer = 0 To datagridview1.Rows.Count - 1
    '        datagridview2.rows.add()
    '        Dim gridrow As datagridViewRow = datagridview1.rows(rowIndex)
    '        datagridview2.Rows(rowIndex).cells(0).value = gridrow.Cells(0).value
    '        datagridview2.Rows(rowIndex).cells(1).value = gridrow.Cells(1).value
    '        datagridview2.Rows(rowIndex).cells(2).value = gridrow.Cells(2).value

    '    Next rowIndex

    'End Sub


    ''转科转归 压疮框自动获取
    'Private Sub XCheckBox64_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '    Dim datagridview1 As XDataGrid = Me.FindControl("XDataGrid4")
    '    Dim datagridview2 As XDataGrid = Me.FindControl("XDataGrid8")

    '    If datagridview1.Rows.Count <= 0 Then
    '        Return
    '    End If
    '    datagridview2.rows.clear()
    '    For rowIndex As Integer = 0 To datagridview1.Rows.Count - 1

    '        datagridview2.rows.add()
    '        Dim gridrow As datagridViewRow = datagridview1.rows(rowIndex)
    '        datagridview2.Rows(rowIndex).cells(0).value = gridrow.Cells(0).value
    '        datagridview2.Rows(rowIndex).cells(1).value = gridrow.Cells(1).value
    '        datagridview2.Rows(rowIndex).cells(2).value = gridrow.Cells(2).value

    '    Next rowIndex
    'End Sub


    '单击组件时发生。
    Private Sub XButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DeleteSelectedRow("XDataGrid6")
    End Sub


    Private Sub DeleteSelectedRow(ByVal gridViewName As String)
        Dim gridView As XDataGrid = Me.FindControl(gridViewName)
        If gridView Is Nothing OrElse gridView.SelectedRows.Count <= 0 Then
            Exit Sub
        End If

        gridView.Rows.Remove(gridView.SelectedRows(0))
    End Sub




End Class
